#include<iostream>
#include<fstream>
#include<boost/mpi.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
using namespace boost::mpi;
#include"sm_system.h"
#include"sm_solver.h"

using std::cout;
using std::cin;
using std::endl;
using std::ofstream;

using namespace SM;

int main()
{
  environment env;
  communicator world;
  System_Tz_HO effV;
  System_Tz_SM_M effVm;
  //System_Tz_HF Vhf;
  System_Tz_Gammow Vgam;

  //System_TzM_HO Vm;
  //System_TzM_HF Vhfm;  

  int N=1;
  int Z=1;
  double Emax;
  int num,Par,MM;
  if(world.rank()==0)
    {
      cin>>N>>Z;
      cin>>Emax;
      string spfile,vfile;
      cin>>spfile>>vfile;


      // effV.setInputFiles(spfile.c_str(),vfile.c_str());
      // effV.setup();

      // Vhf.setup(&effV,N+Z,Z);
      // Vhf.printOrbitals();
      // cout<<Vhf.hfsolver.Energy<<endl;
      //effVm.setup(&Vhf,N+Z);
      

      // Vgam.setup(&effV,N+Z,Z);
      // Vgam.setup();
      // effVm.setup(&Vgam,N+Z);
      Vgam.setupFromFile(spfile.c_str(),vfile.c_str());
      effVm.setup(&Vgam,N+Z);

      //effVm.setup(&effV,N+Z);
      //cin>>effVm.beta;
      // Vm.setup(&effV);
      // cout<<"finish m scheme interaction setup\n";
      // Vhfm.setup(&Vm,N+Z,Z);
      // cout<<"finish hf and setup interaction under hf basis \n";
      // cin>>Vhfm.beta;
      //Vhfm.printOrbitals();
      //cout<<Vhfm.hfsolver.Energy<<endl;
      cin>>num>>Par>>MM;
    }
  broadcast(world,N,0);
  broadcast(world,Z,0);
  broadcast(world,Emax,0);
  broadcast(world,effVm,0);
  broadcast(world,num,0);
  broadcast(world,Par,0);
  broadcast(world,MM,0);
  //broadcast(world,Vhfm,0);  

    
  SMSolver smsolver(world,&effVm,N,Z);//,vN,vZ
  //SMSolver smsolver(world,&Vhfm,N,Z);//,vN,vZ

 // vector<complexd> scales={complexd(2.2,-1.),complexd(2.2,-0.5),complexd(2.2,0.5),complexd(2.2,1)};
  vector<complexd> scales={complexd(1,0.)};
  ofstream fout("summary_scaling.txt",std::ios::app);
  for(int i=0;i<scales.size();i++)
    {
      //effVm.setScaling(scales[i]);

      smsolver.diag_lanczos(num,MM,Par,Emax);//num,MM,Par,Emax,step=1
      //smsolver.diag(0,0,Emax);//MM,Par,Emax

      //if(world.rank()==0)
      //fout<<"scaling: "<<scales[i]<<endl;      
  
      smsolver.printStates(num);
      //  smsolver.calOccuNums(0);
      //  smsolver.printOccuNums();
      //smsolver.printStates(fout,num);
      //if(world.rank()==0)      
//	fout<<endl;
    }  
  return 0;
}
